<?PHP
	// *******************************************************************************************
	// @Namespace : Colibri.Core
	// @Description : Containes helper methods to map URL's in modules.
	// @Author : Ronald Guillen
	// *******************************************************************************************
	
	class UrlMapper
	{
		public $Module = "";
		public $View = "";
		public $Parameters = Array();
		public $Patterns = Array();
		
		private $RequestUrl = NULL;
		
		function  __construct()
		{
			$requestURL = str_replace(REWRITE_BASE,"", $_SERVER["REQUEST_URI"]);
			$this->RequestUrl = preg_split("/\//", $requestURL);
		}
		
		// @ Methods
		function addPattern($pattern = NULL)
		{
			array_push($Patterns, $pattern);
		}
		
		function mapToModule()
		{
			switch(count($this->RequestUrl))
			{
				case 1:
						$this->Module = $this->RequestUrl[0];
						$this->View = "default";
					break;
				case 2:
						$this->Module = $this->RequestUrl[0];
						$this->View = $this->RequestUrl[1];
					break;
				default:
						$this->Module = $this->RequestUrl[0];
						$this->View = $this->RequestUrl[1];
						$this->Parameters = $this->compileParameters($this->RequestUrl);
					break;
			}
		}
		
		// @ Helpers
		function compileParameters($params)
		{
			$tempArray = Array();
			
			for($n = 2; $n < count($params); $n++)
			{
				$tempArray[$n - 2] = $params[$n];
			}
			
			return $tempArray;
		}
	}
	
?>